﻿using System;
using System.Data;
using System.Collections.Generic;
using HsTec.Mobile.Green.Model;
namespace HsTec.Mobile.Green.BLL
{
    /// <summary>
    /// 业务逻辑类Commitment 的摘要说明。
    /// </summary>
    public class CommitmentBLL
    {
        private readonly HsTec.Mobile.Green.DAL.CommitmentDAL dal = new HsTec.Mobile.Green.DAL.CommitmentDAL();
        public CommitmentBLL()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string com_ids)
        {
            return dal.Exists(com_ids);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(HsTec.Mobile.Green.Model.Commitment model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(HsTec.Mobile.Green.Model.Commitment model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(string com_ids)
        {

            return dal.Delete(com_ids);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HsTec.Mobile.Green.Model.Commitment GetModel(int com_id)
        {

            return dal.GetModel(com_id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataView GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataView GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.Commitment> GetModelList(string strWhere)
        {
            DataView ds = dal.GetList(strWhere);
            return DataTableToList(ds.Table);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.CommitmentEntity> GetModelListEntity(string strWhere)
        {
            DataView ds = dal.GetListEntity(strWhere);
            return DataTableToListEntity(ds.Table);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.Commitment> DataTableToList(DataTable dt)
        {
            List<HsTec.Mobile.Green.Model.Commitment> modelList = new List<HsTec.Mobile.Green.Model.Commitment>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HsTec.Mobile.Green.Model.Commitment model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HsTec.Mobile.Green.Model.Commitment();
                    if (dt.Rows[n]["com_id"].ToString() != "")
                    {
                        model.com_id = int.Parse(dt.Rows[n]["com_id"].ToString());
                    }
                    model.professional = dt.Rows[n]["professional"].ToString();
                    if (dt.Rows[n]["departments"].ToString() != "")
                    {
                        model.departments = int.Parse(dt.Rows[n]["departments"].ToString());
                    }
                    if (dt.Rows[n]["completiondate"].ToString() != "")
                    {
                        model.completiondate = DateTime.Parse(dt.Rows[n]["completiondate"].ToString());
                    }
                    if (dt.Rows[n]["deliverydate"].ToString() != "")
                    {
                        model.deliverydate = DateTime.Parse(dt.Rows[n]["deliverydate"].ToString());
                    }
                    if (dt.Rows[n]["reviewer"].ToString() != "")
                    {
                        model.reviewer = int.Parse(dt.Rows[n]["reviewer"].ToString());
                    }
                    if (dt.Rows[n]["branchreviewer"].ToString() != "")
                    {
                        model.branchreviewer = int.Parse(dt.Rows[n]["branchreviewer"].ToString());
                    }
                    model.qualityplan = dt.Rows[n]["qualityplan"].ToString();
                    model.conferencereview = dt.Rows[n]["conferencereview"].ToString();
                    if (dt.Rows[n]["tp_id"].ToString() != "")
                    {
                        model.tp_id = int.Parse(dt.Rows[n]["tp_id"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        public List<HsTec.Mobile.Green.Model.CommitmentEntity> DataTableToListEntity(DataTable dt)
        {
            List<HsTec.Mobile.Green.Model.CommitmentEntity> modelList = new List<HsTec.Mobile.Green.Model.CommitmentEntity>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HsTec.Mobile.Green.Model.CommitmentEntity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HsTec.Mobile.Green.Model.CommitmentEntity();
                    if (dt.Rows[n]["com_id"].ToString() != "")
                    {
                        model.com_id = int.Parse(dt.Rows[n]["com_id"].ToString());
                    }
                    model.professional = dt.Rows[n]["professional"].ToString();
                    if (dt.Rows[n]["departments"].ToString() != "")
                    {
                        model.departments = int.Parse(dt.Rows[n]["departments"].ToString());
                    }
                    if (dt.Rows[n]["completiondate"].ToString() != "")
                    {
                        model.completiondate = DateTime.Parse(dt.Rows[n]["completiondate"].ToString());
                    }
                    if (dt.Rows[n]["deliverydate"].ToString() != "")
                    {
                        model.deliverydate = DateTime.Parse(dt.Rows[n]["deliverydate"].ToString());
                    }
                    if (dt.Rows[n]["reviewer"].ToString() != "")
                    {
                        model.reviewer = int.Parse(dt.Rows[n]["reviewer"].ToString());
                    }
                    if (dt.Rows[n]["branchreviewer"].ToString() != "")
                    {
                        model.branchreviewer = int.Parse(dt.Rows[n]["branchreviewer"].ToString());
                    }
                    model.reviewername = dt.Rows[n]["reviewername"].ToString();
                    model.branchreviewername = dt.Rows[n]["branchreviewername"].ToString();
                    model.deptname = dt.Rows[n]["deptname"].ToString();
                    model.qualityplan = dt.Rows[n]["qualityplan"].ToString();
                    model.conferencereview = dt.Rows[n]["conferencereview"].ToString();
                    if (dt.Rows[n]["tp_id"].ToString() != "")
                    {
                        model.tp_id = int.Parse(dt.Rows[n]["tp_id"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataView GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

